package com.ht.controller;

import com.ht.data.Result;
import com.ht.domin.po.Article;
import com.ht.service.RecommendedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

/**
 * 科普号首页推荐接口
 */
@RestController
@RequestMapping("recommended")
@Api("科普号推荐管理Api")
@RefreshScope //自动刷新配置文件
public class RecommendedController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private RecommendedService recommendedService;

    @GetMapping
    @ApiOperation(value = "查询所有发表文章")
    @ApiImplicitParam(name = "doctor",value = "医生",required = true,paramType = "path")
    public Result findArticle(){
        Result result = recommendedService.findArticle();
        return result;
    }

    /**
     * TODO 自己测试用的
     * @param article
     * @return
     */
    @PostMapping
    @ApiOperation(value = "增加文章")
    @ApiImplicitParam(name = "article",value = "订单实体类",required = true,paramType = "body")
    public Result add(@RequestBody Article article){
        //ArticleBO bo = new ArticleBO(dto);
        Result result = recommendedService.insert(article);
        return result;
    }

    @Scheduled(cron = "*/10 * * * * ?")
    public void test(){
        //判断集合是否存在
        //mongoTemplate.createCollection("article");
        //mongoTemplate.createCollection("collection");
        //mongoTemplate.createCollection("focus");
        mongoTemplate.createCollection("praise");
        System.out.println("OK");
    }

}
